$(function() {
    $('button').click(function() {
        const username = $('#username').val().trim()
        const password = $('#password').val().trim()

        if (!username && !password) {
            layer.alert('填写账号和密码');
            return
        }
        $.ajax({
            url: '/admin/user/login',
            type: 'post',
            data: {
                username,
                password,
            },
            success(res) {
                console.log(res);
                if (res.code === 200) {
                    localStorage.setItem('token', res.token)
                    location.href = 'index.html'
                }
            }

        })
    })
})